package com.atguigu.gulimall.cart.vo;

import lombok.Data;
import lombok.ToString;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.List;
import java.util.Optional;

@Data
public class Cart {
    List<CartItem> items;
    private Integer countNum;
    private Integer countType;
    private BigDecimal totalAmount;
    private BigDecimal reduce=new BigDecimal("0.00");

    public Integer getCountNum() {
            items.stream().map(CartItem::getCount).reduce(Integer::sum).orElse(0);
        return countNum;
    }
    public Integer getCountType() {
        return items.size();
    }
    public BigDecimal getTotalAmount() {
        BigDecimal bigDecimal = items.stream().filter(CartItem::getCheck).map(CartItem::getTotalPrice).reduce(BigDecimal::add).get();
        System.out.println(bigDecimal);
        return bigDecimal;
    }

    public BigDecimal getReduce() {
        return reduce;
    }


    @Data
    @ToString
    public static class CartItem{
        private Long skuId;
        private Boolean check=true;
        private String title;
        private String image;
        private List<String> skuAttr;
        private BigDecimal price;
        private Integer count;
        private BigDecimal totalPrice;
        public BigDecimal getTotalPrice() {
            return this.price.multiply(new BigDecimal("" + this.count));
        }
    }
}
